// @flow
import * as React from 'react';
import '../static/css/windows.css';
import { Menu, Dropdown, Icon } from 'antd';
import { inject, observer } from 'mobx-react';
// const ipcRenderer = require('electron').ipcRenderer
import { ipcRenderer } from 'electron'

@inject('coins')
@observer
export default class Windows extends React.Component<Props> {

  constructor(props) {
    super(props)

    let coinsMiner = this.props.coins.currentCoinsMiner
    let isStable = this.props.coins.currentIsStable
    let version = this.props.coins.currentVersion
    let year = this.props.coins.currentYear;

    this.state = {
      coinsMiner: coinsMiner,
      isStable: isStable,
      version: version,
      year: year,
      // permission: permission
    }
  }

  windowMin() {
    console.log('最小化')
    ipcRenderer.send('window-min')
  }

  windowMax() {
    console.log('最大化')
    ipcRenderer.send('window-max')
  }

  windowClose() {
    console.log('关闭窗口')
    ipcRenderer.send('window-close')
  }

  render() {
    const menu = (
      <Menu className="user-menu">
        <Menu.Item>
          <span onClick={this.props.showRightSlider}>个人信息</span>
        </Menu.Item>
        <Menu.Item>
          <a target="_blank" href="http://www.taobao.com/">更多设置</a>
        </Menu.Item>
        <Menu.Item>
          <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">帮助</a>
        </Menu.Item>
        <Menu.Divider />
        <Menu.Item>
          <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">注销</a>
        </Menu.Item>
      </Menu>
    )
    let permissionCode = this.props.coins.currentPermission
    var max
    var userMenu
    if (permissionCode == 1 || permissionCode == 0) {
      max = ''
      userMenu = ''
      // console.log('windows.jsx 不显示最大化按钮，当前权限码为：'+ permissionCode)
      // console.log(this.state.permission)

    } else if (permissionCode == 2 || permissionCode == 3) {
      // console.log('windows.jsx 显示最大化按钮，权限码为：'+ permissionCode)
      max = (
        <div className="window-max" onClick={this.windowMax}>
          <Icon type="plus-circle" />
        </div>
      )
      
      userMenu = (
        <div className="user-name">
          <Dropdown overlay={menu} placement="bottomRight" size="small">
            <span><Icon type="user" /> admin </span>
          </Dropdown>
        </div>
      )
    }

    return (
      <div className="windows">
        <div className="name-version">
          <span>「&nbsp;{this.state.coinsMiner}&nbsp;」</span>&nbsp;
          <span>{this.state.isStable}</span>&nbsp;
          <span>{this.state.version}</span>&nbsp;
          <span>{this.state.year}</span>&nbsp;
        </div>
        <div className="windows-operation">
          {userMenu}
          <div className="window-min" onClick={this.windowMin}>
            <Icon type="minus-circle" />
          </div>
          {max}
          <div className="window-close" onClick={this.windowClose}>
            <Icon type="close-circle" />
          </div>
        </div>
      </div>
    );
  }
}
